﻿using System;
using System.Composition.Hosting;

namespace Unread.App
{
    public static class ServicesFactory
    {
        private static CompositionHost _compositionHost;

        public static void Initialize(CompositionHost compositionHost)
        {
            if (compositionHost == null) throw new ArgumentNullException("compositionHost");

            _compositionHost = compositionHost;
        }

        public static T GetInstance<T>()
        {
            if (_compositionHost == null) throw new InvalidOperationException("Call Initialize first, before using ServicesFactory");

            return _compositionHost.GetExport<T>();
        }
    }
}
